package org.yankun.exam4j.security.user.service.impl;


import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.yankun.exam4j.common.daobase.DaoBase;
import org.yankun.exam4j.entity.Passport;
import org.yankun.exam4j.entity.User;
import org.yankun.exam4j.security.user.service.UserService;

@Service
public class UserServiceImpl implements UserService {

	@Resource
	private DaoBase<User> dao;
	
	@Override
	public User getUserByPassport(Passport passport) {
		
		String hql = "from User where passport.uid=?";
		
		List<User> userList = dao.hql(hql,1, new Object[]{passport.getUid()});
		
		if(null != userList && !userList.isEmpty()){
			return userList.get(0);
		}
		
		return null;
	}

	@Override
	public User getUserById(Serializable userId) {
		return dao.getHibernateTemplate().get(User.class, userId);
	}

}
